package com.leetcode.problems069;

import java.util.*;

/**
 * https://leetcode-cn.com/problems/sqrtx/
 * @Date 2021/12/09 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution {

    int mySqrt(int x) {
        int l = 0, r = x, ans = -1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if ((long)mid * mid <= x) {
                ans = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return ans;
    }



    public static void main(String[] args) {
        System.out.println(new Solution().mySqrt(8));
    }
}
